#!/bin/bash

is_need_generate() {
  path_includes=(cypress tools)
  diff_names=$(git diff --cached --name-only | grep -oE '^[^/]+/[^/]+' | sort $1 | uniq)
  for e in ${path_includes[@]}; do
    result=$(echo $diff_names | grep $e)
    if [[ $result != "" ]]; then
      echo 1
      return
    fi
  done
  echo 0
}

if [[ $(is_need_generate) == 1 ]]; then
  echo "need generate e2e"
  yarn e2e -g && git add .codebase/pipelines/ci.yaml
else
  echo "don't need generate e2e"
fi
